﻿#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int data;
    struct node* next;
}Node;

// 请在此添加你的代码
/********** Begin *********/
Node* CreatList() {
    int n;
    scanf("%d", &n);
    Node* head = (Node*)malloc(sizeof(Node*));
    Node* p;
    p = head;
    while (n--) {
        Node* newpoint = (Node*)malloc(sizeof(Node*));
        head->next = newpoint;
        scanf("%d", &newpoint->data);
        head = newpoint;
    }
    head->next = NULL;
    return p;
}
void ShowList(Node* p) {
    while (p->next) {
        printf("%d", p->next->data);
        p = p->next;
    }
}
Node* ReverseList(Node* head) {
    Node* newHead;
    if (head == NULL || head->next == NULL) {
        return head;
    }
    newHead = ReverseList(head->next);
    head->next->next = head;
    head->next = NULL;
    return newHead;
}

/**********  End  **********/
int main(void)
{
    Node* phead;
    phead = CreatList();
    printf("链表逆置前的数据:\n");
    ShowList(phead);
    phead = ReverseList(phead);
    printf("链表逆置后的数据:\n");
    ShowList(phead);
    return 0;
}
